package com.guldan.jaina.provider;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.guldan.core.dubbo.client.ResponseDTO;
import com.guldan.core.search.Pagination;
import com.guldan.jaina.dto.dicType.DicTypeDTO;
import com.guldan.jaina.dto.dicType.DicTypeSearchDTO;
import com.guldan.jaina.manager.DicTypeManager;

/**
 * Created by Silas.
 * Date: 2016/11/7
 * Time: 22:54
 */
@Component
public class DicTypeProviderImpl implements IDicTypeProvider {

    @Autowired
    private DicTypeManager dicTypeManager;

    @Override
    public ResponseDTO<DicTypeDTO> get(Integer areaId) {
        ResponseDTO<DicTypeDTO> response = new ResponseDTO<>();
        response.setData(dicTypeManager.get(areaId));
        return response;
    }

    @Override
    public ResponseDTO<DicTypeDTO> save(DicTypeDTO dto) {
        ResponseDTO<DicTypeDTO> response = new ResponseDTO<>();
        try {
            response.setData(dicTypeManager.save(dto));
        } catch (Exception ex) {
            response.setStatus(false);
            response.setException(ex);
        }
        return response;
    }

    @Override
    public ResponseDTO<Boolean> delete(Integer dicTypeId) {
        ResponseDTO<Boolean> response = new ResponseDTO<>();
        response.setData(dicTypeManager.delete(dicTypeId));
        return response;
    }

    @Override
    public ResponseDTO<Pagination<DicTypeDTO>> list(DicTypeSearchDTO dicTypeSearchDTO) {
        ResponseDTO<Pagination<DicTypeDTO>> response = new ResponseDTO<>();
        response.setData(dicTypeManager.list(dicTypeSearchDTO));
        return response;
    }

	@Override
	public ResponseDTO<List<DicTypeDTO>> all(DicTypeSearchDTO dicTypeSearchDTO) {
		ResponseDTO<List<DicTypeDTO>> response = new ResponseDTO<>();
		response.setData(dicTypeManager.all(dicTypeSearchDTO));
		return response;
	}

}
